package com.lzyjkz.quick_components.entity;


import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class Response<T> {
    private Integer code;
    private String msg;
    private T data;

    /** 私有构造方法 */
    private Response() {
    }

    /** 带参数成功返回 */
    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<>();
        response.setCode(200);
        response.setMsg("success");
        response.setData(data);
        return response;
    }

    /** 带信息、带参数成功返回 */
    public static <T> Response<T> success(T data, String msg) {
        Response<T> response = new Response<>();
        response.setCode(200);
        response.setMsg(msg);
        response.setData(data);
        return response;
    }

    /** 无参数成功返回 */
    public static <T> Response<T> success() {
        Response<T> response = new Response<>();
        response.setCode(200);
        response.setMsg("success");
        return response;
    }

    /** 失败返回 */
    public static <T> Response<T> fail(String msg) {
        Response<T> response = new Response<>();
        response.setCode(500);
        response.setMsg(msg);
        return response;
    }

    /** 带消息失败返回 */
    public static <T> Response<T> fail(Integer code, String msg) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
}
